package com.e2oto.seller.modules.launch.presenter;

import com.alibaba.fastjson.JSONObject;
import com.e2oto.seller.common.EasyAES;
import com.e2oto.seller.common.base.BaseBean;
import com.e2oto.seller.common.base.BasePresenter;

import com.e2oto.seller.common.utils.RetrofitUtils;
import com.e2oto.seller.modules.SellerApp;
import com.e2oto.seller.modules.launch.bean.CodeBean;
import com.e2oto.seller.modules.launch.bean.LoginBean;
import com.e2oto.seller.modules.launch.views.ForgetView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by ZhangLiQiang on 2017/11/6.
 */

public class ForgetPresenter extends BasePresenter<ForgetView> {

    /***
     * 发验证码
     * @param mobile
     */
    public void sendCode(String mobile) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mobile", mobile);
        String param = EasyAES.encrypt(jsonObject);
        RetrofitUtils.getApiService().sendForgetPasswd(param, SellerApp.versionName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseBean<CodeBean>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BaseBean<CodeBean> bean) {
                        if (bean.getCode() == 200) {
                            getView().sendCodeResult(bean.getData());
                        } else {
                            getView().showMessage(bean.getMsg());
                        }

                    }

                    @Override
                    public void onError(Throwable e) {
                        getView().showMessage(e.toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }

}
